public class L538 {

    class Solution {
        int sum;

        public TreeNode convertBST(TreeNode root) {
            traversal(root);
            return root;
        }

        private void traversal(TreeNode root) {
            if (root == null) {
                return;
            }
            traversal(root.right);
            root.val += sum;
            sum = root.val;
            traversal(root.left);

        }
    }
}
